﻿using System;

namespace Wala.Common.Chats
{
    public class SMS
    {
        public Object LockTimer = new Object();

        private int iD;
        public int ID
        {
            get
            {
                return iD;
            }
            set
            {
                iD = value;
            }
        }

        private String body;
        public String Body
        {
            get
            {
                return body;
            }
            set
            {
                body = value;
            }
        }

        private bool isMine;
        public bool IsMine
        {
            get
            {
                return isMine;
            }
            set
            {
                isMine = value;
            }
        }

        private bool isRead;
        public bool IsRead
        {
            get
            {
                return isRead;
            }
            set
            {
                isRead = value;
            }
        }

        private int sendStatus;
        public int SendStatus
        {
            get
            {
                return sendStatus;
            }
            set
            {
                sendStatus = value;
            }
        }

        private uint receivedTime;
        public uint ReceivedTime
        {
            get
            {
                return receivedTime;
            }
            set
            {
                receivedTime = value;
            }
        }

        private uint friendId; // sender or receiverId
        public uint FriendId
        {
            get
            {
                return friendId;
            }
            set
            {
                friendId = value;
            }
        }

        private uint sentTime;
        public uint SentTime
        {
            get
            {
                return sentTime;
            }
            set
            {
                sentTime = value;
            }
        }

        private int groupId;
        public int GroupId
        {
            get
            {
                return groupId;
            }
            set
            {
                groupId = value;
            }
        }

        private uint type; //1 text; 6 location; 10 voice; 12 image; 16 html/gif; 
        public uint Type
        {
            get
            {
                return type;
            }
            set
            {
                type = value;
            }
        }

        private String friendName;
        public String FriendName
        {
            get
            {
                return friendName;
            }
            set
            {
                friendName = value;
            }
        }
        //temp
        private String uploadingPercentage = "0";

        public String UploadingPercentage
        {
            get
            {
                return uploadingPercentage;
            }
            set
            {
                uploadingPercentage = value;
            }
        }

        private long coreMessageId;

        public long CoreMessageId
        {
            get
            {
                return coreMessageId;
            }
            set
            {
                coreMessageId = value;
            }
        }

        public static SMS newInstance(String body, bool isMine, int sendStatus, uint friendId, int groupId, uint type)
        {
            DateTime dateTime = DateTime.Now;
            uint totalSecond = 0;
            DateTime time = new DateTime(1970, 1, 1, 7, 0, 0);
            TimeSpan timeSpan = dateTime - time;
            totalSecond = Convert.ToUInt32(timeSpan.TotalSeconds);

            return new SMS(0, body, isMine, true, sendStatus,totalSecond, friendId,
                totalSecond, groupId, type);
        }

        public SMS(int iD, String body, bool isMine, bool isRead,
            int sendStatus, uint receivedTime, uint friendId, uint sentTime, int groupId,
            uint type)
        {
            ID = iD;
            this.body = body;
            this.isMine = isMine;
            this.isRead = isRead;
            this.sendStatus = sendStatus;
            this.receivedTime = receivedTime;
            this.friendId = friendId;
            this.sentTime = sentTime;
            this.groupId = groupId;
            this.type = type;
        }

        public int CompareTo(SMS another)
        {
            if (another.receivedTime > receivedTime)
                return -1;
            if (another.receivedTime < receivedTime)
                return 1;
            return 0;
        }
    }
}
